package example;

import db.domain.User;
import db.domain.UserMeta;
import org.junit.Test;
import sf.database.jdbc.sql.SQLContext;
import sf.dsl.example.Example;
import sf.dsl.example.ExampleSQL;
import sf.dsl.example.SelectOpt;
import sf.dsl.example.SimpleTable;
import sf.dsl.example.WrapperSimpleField;

public class ExampleTest3 {
    @Test
    public void t1() {
        User user = new User();
        user.useQuery().createCriteria().eq(User.Field.id, 1).and().eq(User.Field.displayName, "222");
        SQLContext context = ExampleSQL.getSelectSQLContext(user.useQuery(), null, SelectOpt.all, false);
        System.out.println(context.getSql());
        System.out.println(context.getParas());


        SimpleTable t1 = new SimpleTable(User.class);
        SimpleTable t2 = new SimpleTable(UserMeta.class);
        Example e1 = new Example().select(t1.c(User.Field.id),t1.c(User.Field.age).as("olg"),
                new WrapperSimpleField(new Example().select(t2.c(UserMeta.Field.value)).from(t2).where(t2.c(UserMeta.Field.id).eq(1))).as("cc")
                ).from(t1.as("t1"));
        context = ExampleSQL.getSelectSQLContext(e1, null, SelectOpt.all, false);
        System.out.println(context.getSql());
        System.out.println(context.getParas());
    }
}
